package com.chukun.tx.message.producer;

import com.chukun.tx.constants.MessageConstant;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.client.producer.SendCallback;
//import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author chukun
 * 订单发送消息
 */
@Component
public class OrderProducer {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderProducer.class);

    @Autowired
    private MsgProducer msgProducer;
//    private DefaultMQProducer producer;

    private OrderProducer() {
//        this.producer = new DefaultMQProducer(MessageConstant.ORDER_MQ_GROUP);
//        this.producer.setNamesrvAddr(MessageConstant.DOUBLE_NAME_SERVER);
//        this.producer.setSendMsgTimeout(3000);
//        start();
    }

//    public void start() {
//        try {
//            this.producer.start();
//        } catch (MQClientException e) {
//            LOGGER.error("OrderProducer start error ",e);
//            throw new RuntimeException(e);
//        }
//    }
    /**
     * 发送消息
     * @param message
     */
    public boolean sendMessage(String message) {
        try {
            this.msgProducer.send2TopicTestAQueue(message);
            return true;
        }catch (Exception e) {
            LOGGER.error("OrderProducer sendMessage error",e);
            return false;
        }
    }

    /**
     * 发送消息
     * @param message
     */
    public boolean sendMessage(String message,long timeout) {
        try {
            this.msgProducer.send2TopicTestAQueue(message);
            return true;
        }catch (Exception e) {
            LOGGER.error("OrderProducer sendMessage error",e);
            return false;
        }
    }


    /**
     * 发送消息
     * @param message
     */
//    public boolean sendMessage(String message, long timeout, SendCallback sendCallback) {
//        try {
//            this.msgProducer.send2TopicTestAQueue(message);
//            return true;
//        }catch (Exception e) {
//            LOGGER.error("OrderProducer sendMessage error",e);
//            return false;
//        }
//    }


}
